<template>
  <div class="content">
    <div v-for="(item, index) in list" :key="index" class="Datalist">
      <div class="filename"><span>文件名称:</span>{{ item.filename }}</div>
      <el-row type="flex" class="row-bg">
        <div class="uploadInstitution jigou">
          <span>上传机构:</span>{{ item.uploadInstitution }}
        </div>
        <div class="uploadInstitution jigou">
          <span>上传时间:</span>{{ item.uploadTime }}
        </div>
      </el-row>

      <el-row type="flex" class="row-bg">
        <div class="uploadInstitution jigou">
          <span class="bold">所属地区:</span>{{ item.district }}
        </div>
        <div class="uploadInstitution jigou">
          <span>所属专题:</span>{{ item.topic | topicFormat }}
        </div>
      </el-row>
      <div class="uploadInstitution">
        <span class="bold">文件摘要:</span>{{ item.summary }}
      </div>

      <el-row type="flex" class="row-btn">
        <el-button
          type="primary"
          icon="el-icon-document"
          round
          size="small"
          @click="opendialog(item.id)"
          >详细信息</el-button
        >

        <el-button
          type="warning"
          icon="el-icon-download"
          round
          size="small"
          @click="fileDownloadById(item.id, item.filename)"
          >下载</el-button
        >

      <!-- <el-button
          type="danger"
          icon="el-icon-delete"
          round
          size="small"
          @click="filedelById(item.id)"
          >删除</el-button
        > -->
      </el-row>

      <!-- 点击弹框查看详情 -->
      <el-dialog
        title="查看详情"
        :visible.sync="dialogVisible"
        width="40%"
        class="dialog"
      >
        <el-table :data="gridData">
          <el-table-column property="date" width="140"></el-table-column>
          <el-table-column property="name" width=""></el-table-column>
        </el-table>
        <span slot="footer" class="dialog-footer">
          <!-- <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button> -->
        </span>
      </el-dialog>
    </div>

    <el-pagination
      class="paging"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="currentPage1"
      :page-size="pagesize"
      layout="total, prev, pager, next"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
import { gettopicsearchData } from "../../../Api/api"; //调用按专题浏览文件接口
import { gettopicdetailData } from "../../../Api/api"; //查看详情
import { gettopicuploadData,prefix} from "../../../Api/api"; //下载
// import { gettopicdelData } from "../../Api/api";//删除
// import $ from 'jquery'
import axios from "axios";

export default {
  filters: {
    topicFormat(value) {
      let text =
        value === "0"
          ? "防洪抗旱"
          : value === "1"
          ? "河流水系"
          : value === "2"
          ? "水环境"
          : value === "3"
          ? "水利工程"
          : value === "4"
          ? "水文"
          : value === "5"
          ? "水资源"
          : value === "6"
          ? "统计年鉴"
          : value === "7"
          ? "政策规划"
          : value === "8"
          ? "地理空间"
          : value === "9"
          ? "其他"
          : "";
      // let text = value === '0' ? '防洪抗旱' : (value === '1' ? '河流水系':(value === '2' ? '水环境' :'')),
      return text;
    },
  },
  data() {
    return {
      currentPage1: 1, //当前页数
      pagesize: 10, //    每页的数据
      total: 0, //默认数据总数
         mapPathRoot: prefix, //默认路径
      gridData: [
      ],
      dialogVisible: false,
      list: [
      ],
      params: {
        topic: "4",
        startNum: 0,
        sortBy: "uploadTime",
        //  sortBy: "",
        sortOrder: 0,
        pagesize: 10,
        // query: ''
      },
    };
  },
  mounted() {
    // 页面创建的时候，就执行相关的方法
    this.init();
  },

  methods: {
    //显示列表信息
    init() {
      let that = this;
      gettopicsearchData(this.params).then(function (res) {
        //  console.log(res.data.data);
        if (res.status === 200 && res.data.code === 0) {
          that.list = res.data.data;
          //分页总数
          that.total = res.data.num;
        }
      });
    },
    opendialog(id) {
      console.log(id);
      this.dialogVisible = true;
      let that = this;
      // 在這調用詳情數據
      gettopicdetailData({ id: id }).then(function (res) {
        if (res.status === 200 && res.data.code === 0) {
          that.gridData = [
            {
              date: "文件名称:",
              name: res.data.data.filename,
            },
            {
              date: "上传机构:",
              name: res.data.data.uploadInstitution,
            },
            {
              date: "上传时间",
              name: res.data.data.uploadTime,
            },
            {
              date: "文件摘要",
              name: res.data.data.summary,
            },
            {
              date: "所属地区",
              name: res.data.data.district,
            },
            {
              date: "所属专题",
              name: res.data.data.topic === "4" ? "水文" : "",
            },
            {
              date: "上传者",
              name: res.data.data.uploader,
            },
            {
              date: "文件统计起始时间",
              name: res.data.data.startTime,
            },
            {
              date: "文件统计终止时间",
              name: res.data.data.endTime,
            },
            {
              date: "文件大小",
              name: res.data.data.fileSize,
            },
            {
              date: "文件类型",
              name: res.data.data.fileType,
            },
          ];
        }
      });
    },
    //下载
    fileDownloadById(id) {
      let that = this;
     let url = this.mapPathRoot + "download/ById?id=" + id;
      const a = document.createElement("a");
      a.style.display = "none";
      // a.download = filename;
      // console.log(a.download)
      a.href = url;
      a.click();
      // gettopicuploadData({id:id}).then(function (res) {
      //   console.log(res.data);
      // })
    },
    //删除
    // filedelById(id) {
    //   this.$confirm("确认删除吗?", "提示", {
    //     confirmButtonText: "确定",
    //     cancelButtonText: "取消",
    //     type: "warning",
    //   })
    //     .then(() => {
    //       let that = this;
    //       let msg = { idList: id };
    //       gettopicdelData(msg).then(function (res) {
    //         console.log(msg);
    //         if (res.status === 200) {
    //           that.$message({
    //             type: "success",
    //             message: "删除成功!",
    //           });
    //           that.init();
    //         }
    //       });
    //     })
    //     .catch(() => {
    //       this.$message({
    //         type: "info",
    //         message: "已取消删除",
    //       });
    //     });

    // },


    //分页
    handleSizeChange: function (currentPage) {
      currentPage = this.pagesize;
      console.log(this.pagesize);
    },
    handleCurrentChange: function (currentPage) {
      //点击第几页
      this.currentPage = currentPage;
      this.params.startNum = (this.currentPage - 1) * this.pagesize;
      //  this.params.pagesize=this.currentPage;
      this.init();
      console.log(this.currentPage); //点击第几页
    },
  },
};
</script>

<style scoped>
.content {
  margin-left: 50px;
}
.filename {
  font-size: 16px;
  color: #0066cc;
  font-weight: bold;
}
.jigou {
  width: 260px;
}
.Datalist {
  border-bottom: 1px solid #e5e5e5;
  padding-bottom: 10px;
  padding-top: 10px;
}
.Datalist span {
  padding-right: 10px;
}
.bold {
  font-weight: bold;
}

.uploadInstitution {
  margin-top: 14px;
  margin-bottom: 10px;
  font-size: 14px;
  color: #666;
}
.row-btn {
  margin-top: 14px;
  margin-bottom: 10px;
}
</style>
<style>
.dialog .el-table thead {
  display: none;
}
.dialog .el-dialog__body {
  padding: 0px 20px;
}
.paging {
  text-align: center;
  margin-top: 30px;
}
</style>
